
/**
* @module http.common
* @author: Hjava
* @description: HTTP模块通用接口
* @since: 2018-07-22 15:43:25
*/
Object.defineProperty(exports, "__esModule", { value: true });
var http_core_1 = __webpack_require__(/*! _http/http.core */ "./src/core/http/http.core.ts");
var axios_1 = __webpack_require__(/*! axios */ "./node_modules/axios/index.js");
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var deviceInfo_1 = __webpack_require__(/*! _util/deviceInfo */ "./src/core/utils/deviceInfo.ts");
var promise_1 = __webpack_require__(/*! _util/promise */ "./src/core/utils/promise.ts");
var log_1 = __webpack_require__(/*! ./../utils/log */ "./src/core/utils/log.ts");
var DX_FILE_URL = {
    test: ['api.xm.test.sankuai.com/pan/dl'],
    // 线上与 st 环境数据共通,默认可以访问
    st: ['api.xm.st.sankuai.com/pan/dl', 'file.neixin.cn'],
    online: ['api.xm.st.sankuai.com/pan/dl', 'file.neixin.cn']
};
var HTTPCommon = /** @class */ (function () {
    function HTTPCommon() {
    }
    // IM/PUB 删除服务端会话,接口文档:http://service.sankuai.com/#/services/com.sankuai.xm.xmnew.msgapi/docs/com.sankuai.xm.msg.api.controller.MsgController_restful/com.sankuai.xm.msg.api.controller.MsgController.deleteChatForChannel(com.alibaba.fastjson.JSONObject%252C%2520javax.servlet.http.HttpServletRequest%252C%2520javax.servlet.http.HttpServletResponse)
    HTTPCommon.prototype.deleteRemoteSession = function (options) {
        http_core_1.default.request('/fusion/message/v1/chat/delete/channel', options);
    };
    /**
     *  设置 Native PushToken
     * @param options
     */
    HTTPCommon.prototype.setPushToken = function (options) {
        http_core_1.default.request('/token/api/v1/set', options);
    };
    /**
     * 清除 Native PushToken
     * @param options
     */
    HTTPCommon.prototype.deletePushToken = function (options) {
        http_core_1.default.request('/token/api/v1/del', options);
    };
    HTTPCommon.prototype.shouldSetHeadersWhenGetFileBlob = function (_a) {
        var url = _a.url, _b = _a.env, env = _b === void 0 ? userData_1.default.get('env') : _b;
        return DX_FILE_URL[env].findIndex(function (element) {
            if (url) {
                return url.indexOf(element) > -1;
            }
            else {
                return false;
            }
        }) > -1;
    };
    // 测试数据: {url:'https://api.xm.test.sankuai.com/pan/dl/pan/im/2/image/AhoA_I9QN4TWqigDT2S_MUdNvWzk0_ZfTikthLIq_BnNWU7B_v7JfoR3aR9P_iTFAg?ot=1&w=640&h=708', token:'e9b6e646f802a28d4533f3c21082ec4eac7df09f'}
    HTTPCommon.prototype.getFileBlob = function (_a) {
        var _b = _a.url, url = _b === void 0 ? '' : _b, _c = _a.token, token = _c === void 0 ? void 0 : _c;
        var headers = {};
        var env = userData_1.default.get('env');
        if (!url) {
            log_1.default.error('文件 url 为空');
            return promise_1.default.resolve();
        }
        if (this.shouldSetHeadersWhenGetFileBlob({ url: url, env: env })) {
            headers = {
                'X-Xmftk': token,
                ai: userData_1.default.get('appId'),
                dt: deviceInfo_1.default.deviceType,
                u: userData_1.default.get('uid'),
                uu: userData_1.default.get('deviceId'),
                ck: userData_1.default.get('xsid'),
                al: userData_1.default.get('altoken'),
            };
        }
        log_1.default.log('HTTPCommon::getFileBlob url:' + url + ' token:' + token);
        // 此处由业务来进行错误捕获和处理
        return axios_1.default({
            url: url,
            method: 'GET',
            responseType: 'blob',
            headers: headers
        }).then(function (res) {
            log_1.default.log('HTTPCommon::getFileBlob res:' + res);
            return res.data;
        });
    };
    HTTPCommon.prototype.getAuthFreeTempFileURL = function (options) {
        return http_core_1.default.request('/file/sign_for_authfree_url', options);
    };
    // https://km.sankuai.com/page/276833864#id-%E8%8E%B7%E5%8F%96%E8%A1%A8%E6%83%85%E5%8C%85%E9%85%8D%E7%BD%AE
    HTTPCommon.prototype.getEmoticonsPackages = function (options) {
        return http_core_1.default.request('/uinfo/api/v1/stickerConf/getPackages', options);
    };
    HTTPCommon.prototype.getOneEmoticonsSticker = function (options) {
        return http_core_1.default.request('/uinfo/api/v1/stickerConf/getOneSticker', options);
    };
    return HTTPCommon;
}());
exports.default = new HTTPCommon();


//# sourceURL=webpack://MTDX/./src/core/http/http.common.ts?